package org.p2psimulator.entity;


import org.p2psimulator.entity.behavior.BehaviorTypes;
import org.p2psimulator.entity.protocol.messages.MessageTypes;
import org.p2psimulator.events.Event;



@SuppressWarnings ("unchecked")
public abstract class Message  implements Event{


	private Id origin;

	private Id destination;

	private Id serventId;  // peer que originou a mensagem

	private int TTL = 7;
	private int HOP = 0;

	private int  transactionId;

	protected BehaviorTypes originBehavior;

	public Message(Id  origin, Id  destination, int  transactionId, BehaviorTypes originBehavior){
		this.destination = destination;
		this.origin = origin;
		this.transactionId = transactionId;
		this.originBehavior = originBehavior;
	}

	public Id getListenerId() {

		return destination;
	}

	public Id getDestination() {
		return destination;
	}

	public void setDestination(Id destination) {
		this.destination = destination;
	}

	public Id getOrigin() {
		return origin;
	}

	public void setOrigin(Id origin) {
		this.origin = origin;
	}

	public int getTransactionId() {
		return transactionId;
	}

	public void setTransactionId(int transactionId) {
		this.transactionId = transactionId;
	}

	public void setServentId(Id serventId) {
		this.serventId = serventId;
	}
	public Id getServentId(){
		return this.serventId;
	}

	public int getTTL() {
		return TTL;
	}

	public void setTTL(int ttl) {
		TTL = ttl;
	}

	public void decTTL(){
		TTL--;
	}

	public void incHOP(){
		HOP++;
	}
	public abstract String getName();

        @Override
	public void finalize(){
//		SystemLogger.logger.info("(GC) Mensagem Coletada: " + getName());
		this.origin = null;
		this.destination = null;
	}

	public int getHOP() {
		return HOP;
	}

	public void setHOP(int hop) {
		HOP = hop;
	}

	public String getMessageId(){
		return getName() + transactionId;
	}

	public abstract MessageTypes getMessageType();

	public BehaviorTypes getOriginBehavior() {
		return originBehavior;
	}

	public void setOriginBehavior(BehaviorTypes originBehavior) {
		this.originBehavior = originBehavior;
	}

}
